<?php
namespace App\Services;
use App\Models\UserViewHistory;
use Carbon\Carbon;

class UserViewHistoryService {

    public static function store($user_id, $cookbook_id) {
        $one = UserViewHistory::where('user_id', $user_id)->where('cookbook_id', $cookbook_id)->first();
        if (!$one) {
            UserViewHistory::create([
                'user_id' => $user_id,
                'cookbook_id' => $cookbook_id
            ]);
        } else {
            $one->updated_at = Carbon::now();
            $one->save();
        }
    }

}
